package com.pencilisland.pay.api.service.impl;

import java.io.InputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aliyun.oss.OSSClient;
import com.pencilisland.pay.api.config.AppConfig;
import com.pencilisland.pay.api.service.AliOssService;

@Service
public class AliOssServiceImpl implements InitializingBean, AliOssService {

	private static String endpoint = "http://oss-cn-beijing.aliyuncs.com";

	@Autowired
	private AppConfig config;

	OSSClient ossClient;

	Logger log = LoggerFactory.getLogger(getClass());

	@Override
	public void afterPropertiesSet() throws Exception {
		ossClient = new OSSClient(endpoint, config.getAliyunAppKey(), config.getAliyunAppSecret());
	}

	/* (non-Javadoc)
	 * @see com.pencilisland.pay.api.service.impl.AliOssService#putOss(java.lang.String, java.io.InputStream)
	 */
	@Override
	public void putOss(String key, InputStream input) {
		ossClient.putObject(config.getOssBucket(), key, input);
	}

}
